home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / ispell-3.1.18src / zapdups.x (.txt) < prev   
Microsoft Windows Help File Content  |  1995-01-23  |  5KB  |  140 lines

  1. : Use /bin/sh
  2. # $Id: zapdups.X,v 1.6 1995/01/08 23:23:58 geoff Exp $
  3. # Copyright 1993, Geoff Kuenning, Granada Hills, CA
  4. # All rights reserved.
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. # 1. Redistributions of source code must retain the above copyright
  9. #    notice, this list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. #    notice, this list of conditions and the following disclaimer in the
  12. #    documentation and/or other materials provided with the distribution.
  13. # 3. All modifications to the source code must be clearly marked as
  14. #    such.  Binary redistributions based on modified source code
  15. #    must be clearly marked as modified versions in the documentation
  16. #    and/or other materials provided with the distribution.
  17. # 4. All advertising materials mentioning features or use of this software
  18. #    must display the following acknowledgment:
  19. #      This product includes software developed by Geoff Kuenning and
  20. #      other unpaid contributors.
  21. # 5. The name of Geoff Kuenning may not be used to endorse or promote
  22. #    products derived from this software without specific prior
  23. #    written permission.
  24. # THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
  25. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. # ARE DISCLAIMED.  IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
  28. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. # SUCH DAMAGE.
  35. # Report or get rid of duplicates in various components of a dictionary.
  36. # Usage:
  37. #    zapdups [-d [-n]] [-l langfile] dict-0 dict-1 ...
  38. # Dictionaries starting with dict-1 (not dict-0!) are examined,
  39. # looking for words that appear in any earlier dictionary.  If any
  40. # duplicates are found, they are reported to the standard output.
  41. # If the -d switch is specified, duplicates are removed from later
  42. # dictionaries.  The modification is done in-place.  This switch
  43. # should normally be used after examining the output of an earlier
  44. # run.  The -d switch takes a long time to run, because it uses
  45. # munchlist to reduce the dictionary once duplicates are removed.
  46. # The -n switch can be used to suppress the running of munchlist, to
  47. # save time.
  48. # If the -l switch is specified, the language tables are gotten from
  49. # the specified file; otherwise they come from $LIBDIR/!!DEFLANG!!.
  50. # $Log: zapdups.X,v $
  51. # Revision 1.6  1995/01/08  23:23:58  geoff
  52. # Support variable hashfile suffixes for DOS purposes.
  53. # Revision 1.5  1994/01/25  07:12:24  geoff
  54. # Get rid of all old RCS log lines in preparation for the 3.1 release.
  55. LIBDIR=!!LIBDIR!!
  56. TDIR=${TMPDIR-/usr/tmp}
  57. TMP=${TDIR}/zd$$
  58. SORTTMP="-T ${TDIR}"            # !!SORTTMP!!
  59. USAGE="zapdups [-d [-n]] [-l langfile] dict-0 dict-1 ..."
  60. delete=no
  61. munchit=yes
  62. langtabs=${LIBDIR}/!!DEFLANG!!
  63. while :
  64.     case "$1" in
  65.         delete=yes
  66.         shift
  67.         ;;
  68.         langtabs="$2"
  69.         shift; shift
  70.         ;;
  71.         munchit=no
  72.         shift
  73.         ;;
  74.         echo "$USAGE" 1>&2
  75.         exit 1
  76.         ;;
  77.         break
  78.         ;;
  79.     esac
  80. if [ $# -lt 2 ]
  81.     echo "$USAGE" 1>&2
  82.     exit 1
  83. FAKEHASH=$TMP.a!!HASHSUFFIX!!
  84. FAKEDICT=$TMP.b
  85. SEEN=$TMP.c
  86. LATEST=$TMP.d
  87. DUPS=$TMP.e
  88. trap "rm -f $TMP.*; exit 1" 1 2 15
  89. trap "rm -f $TMP.*; exit 0" 13
  90. # Create a dummy dictionary to hold a compiled copy of the language
  91. # tables.
  92. echo 'QQQQQQQQ' > $FAKEDICT
  93. buildhash -s $FAKEDICT $langtabs $FAKEHASH \
  94.   ||  (echo "Couldn't create fake hash file" 1>&2; rm -f $TMP.*; exit 1) \
  95.   ||  exit 1
  96. rm -f ${FAKEDICT}*
  97. # Expand dictionary 0 into a temp file
  98. ispell -e -d $FAKEHASH < "$1" \
  99.   | tr ' ' "$nl" \
  100.   | sort $SORTTMP -u \
  101.   | sed 's@$@    '"$1@" \
  102.   > $SEEN
  103. shift
  104. # For each subsequent dictionary:
  105. #    (1) Expand it into a temp file
  106. #    (2) Use join to report the duplicates
  107. #    (3) If we are editing, use comm to remove the duplicates
  108. #    (4) Add the expanded dictionary (sans duplicates) to the list
  109. #        of words already seen.
  110. for dict
  111.     ispell -e -d $FAKEHASH < "$dict" \
  112.       | tr ' ' "$nl" \
  113.       | sort $SORTTMP -u \
  114.       | sed 's@$@    '"$dict@" \
  115.       > $LATEST
  116.     join '-t    ' $SEEN $LATEST > $DUPS
  117.     if [ -s $DUPS ]
  118.     then
  119.     cat $DUPS
  120.     if [ $delete = yes ]
  121.     then
  122.         sed "s@    .*    $dict@    $dict@" $DUPS \
  123.           | comm -23 $LATEST - \
  124.           | sed "s@    $dict@@" \
  125.           | if [ $munchit = yes ]
  126.         then
  127.             munchlist -l "$langtabs" > "$dict"
  128.         else
  129.             sort $SORTTMP -u -o "$dict"
  130.     fi
  131.     # We must do a shift so that $# remains correct
  132.     shift
  133.     if [ $# -gt 0 ]
  134.     then
  135.     sort $SORTTMP -u -o $SEEN $LATEST $SEEN
  136.     fi
  137. done \
  138.   | sort -u
  139. rm -f $TMP.*
  140.